package com.atguigu.service.impl;

import com.atguigu.base.BaseMapper;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.entity.House;
import com.atguigu.entity.bo.HouseQueryBo;
import com.atguigu.entity.vo.HouseVo;
import com.atguigu.mapper.DictMapper;
import com.atguigu.mapper.HouseMapper;
import com.atguigu.service.HouseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Date:2022/11/4
 * Author:ybc
 * Description:
 */
@DubboService
public class HouseServiceImpl extends BaseServiceImpl<House> implements HouseService {

    @Autowired
    private HouseMapper houseMapper;
    @Autowired
    private DictMapper dictMapper;

    @Override
    public BaseMapper<House> getBaseMapper() {
        return houseMapper;
    }

    @Override
    public House getById(Long id) {
        House house = houseMapper.getById(id);
        house.setHouseTypeName(dictMapper.getDictNameById(house.getHouseTypeId()));
        house.setFloorName(dictMapper.getDictNameById(house.getFloorId()));
        house.setDirectionName(dictMapper.getDictNameById(house.getDirectionId()));
        house.setDecorationName(dictMapper.getDictNameById(house.getDecorationId()));
        house.setHouseUseName(dictMapper.getDictNameById(house.getHouseUseId()));
        house.setBuildStructureName(dictMapper.getDictNameById(house.getBuildStructureId()));
        return house;
    }

    @Override
    public PageInfo<HouseVo> findHouseVoPage(Integer pageNum, Integer pageSize, HouseQueryBo houseQueryBo) {
        PageHelper.startPage(pageNum, pageSize);
        List<HouseVo> list = houseMapper.findHouseVoPage(houseQueryBo);
        for (HouseVo houseVo : list) {
            houseVo.setHouseTypeName(dictMapper.getDictNameById(houseVo.getHouseTypeId()));
            houseVo.setFloorName(dictMapper.getDictNameById(houseVo.getFloorId()));
            houseVo.setDirectionName(dictMapper.getDictNameById(houseVo.getDirectionId()));
        }
        return new PageInfo<>(list, 10);
    }
}
